'use strict';

stareal
    .controller("VenusController", function ($scope, $stateParams, $api, $sce, base64, $state, $alert,localStorageService,$timeout,$lazyLoader,$location, $anchorScroll) {
        //获取城市  app/city/list
        var h=$(window).height()-2.5*parseFloat(document.documentElement.style.fontSize)+"px";
        $("#wrapper_container").height(h);
        $scope.longitude=localStorageService.get('longitude');//当前的位置
        $scope.latitude=localStorageService.get('latitude');//当前的位置
        $scope.cityid=$stateParams.cityid;
        $scope.distance=$stateParams.distance;
        $scope.score=$stateParams.score;
        $scope.cityName=$stateParams.cityName;
        $scope.selectID=0;
        $scope.stauts1=false;
        $scope.stauts2=false;
        $scope.stauts3=false;
        if($scope.cityid==''){
            $scope.text1='城市';
        }else{
            $scope.text1=$scope.cityName;
        }
        if($scope.distance==''){
            $scope.text2='距离';
        }else if($scope.distance==0){
            $scope.text2='所有';
        }else if($scope.distance!=''){
            $scope.text2=$scope.distance;
        }
        if($scope.score==''){
            $scope.text3='评分';
        }else if($scope.score==1){
            $scope.text3='从高到低';
        }else if($scope.score==2){
            $scope.text3='从低到高';
        }
        $scope.getCureenCity=function(){
            $api.get("app/city/list",{}, true)
                .then(function(ret){
                    $scope.saiCities=ret.data;
                })
        }
        $scope.getCureenCity();
        //    下拉分类

        var refresh = function(kid){
            $state.go('main.venus',{longitude:$scope.longitude,cityid:$scope.cityid,distance:$scope.distance,score:$scope.score,cityName:$scope.cityName,latitude: $scope.latitude},true);
        };
        $scope.switchnavSelect=function(idnx,status){
            $scope.selectID=idnx;
            if($scope.selectID==1){
                $scope.stauts2=false;
                $scope.stauts3=false;
                if($scope.stauts1==false){
                    $scope.stauts1=true;
                }else{
                    $scope.stauts1=false;
                }
            }else if($scope.selectID==2){
                $scope.stauts1=false;
                $scope.stauts3=false;
                if($scope.stauts2==false){
                    $scope.stauts2=true;
                }else{
                    $scope.stauts2=false;
                }
            }else if($scope.selectID==3){
                $scope.stauts1=false;
                $scope.stauts2=false;
                if($scope.stauts3==false){
                    $scope.stauts3=true;
                }else{
                    $scope.stauts3=false;
                }
            }
        }
        //选中筛选的条件
        $scope.changesnav=function(idnx,text,cid){
            $scope.selectID=idnx;
            if($scope.selectID==1){
                $scope.stauts1=false;
                $scope.stauts2=false;
                $scope.stauts3=false;
                $scope.text1=text;
                $scope.cityid=cid;
                $scope.cityName=text;
               refresh();
            }else if($scope.selectID==2){
                $scope.stauts1=false;
                $scope.stauts2=false;
                $scope.stauts3=false;
                $scope.text2=text;
                $scope.distance=cid;
               refresh();
            }else if($scope.selectID==3){
                $scope.stauts1=false;
                $scope.stauts2=false;
                $scope.stauts3=false;
                $scope.text3=text;
                $scope.score=cid;
               refresh();
            }
        }
        $scope.getDistance=function(long,lat){
            // console.log(long);
            // console.log(lat);
            if(long==undefined||long==''||long==null||lat==undefined||lat==''||lat==null){
                return '暂无'
            }else if( $scope.longitude==undefined||$scope.longitude==null||$scope.longitude==''||$scope.latitude==null||$scope.latitude==''||$scope.latitude==undefined){
                return '暂无'
            }else{
                var p1 = [long, lat];
                var p0 = [ $scope.longitude,$scope.latitude];
                var dis = AMap.GeometryUtil.distance(p1, p0); //米
                return (dis/1000).toFixed(2)+'km' ;
            }

        }
       // $scope.getDistance();
           //场馆列表 app/site/list
        $scope.venusgoods = new $lazyLoader("app/site/list",
            {longitude:$scope.longitude,cityid:$scope.cityid,distance:$scope.distance,score:$scope.score,cityName:$scope.cityName,latitude: $scope.latitude}, true);
        $scope.venusgoods.nextPage();

        $scope.sortscity=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','R','S','T','U','V','W','X','Y','Z'];
        $scope.gotoBottom = function(id) {
            //   console.log(id);
            // 将location.hash的值设置为
            // 你想要滚动到的元素的id
            $location.hash(id);

            // 调用 $anchorScroll()
            $anchorScroll();
        };
    });